package com.yuhq.service.impl;

import com.yuhq.mapper.ProjectInfoMapper;
import com.yuhq.model.ProjectInfo;
import com.yuhq.service.ProjectInfoService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sam
 */
@Service("projectInfoService")
public class ProjectInfoServiceImpl implements ProjectInfoService {

    @Resource
    private ProjectInfoMapper projectInfoMapper;

    @Override
    public List<ProjectInfo> findByStatus(Integer status) {
        Map<String, Object> param = new HashMap<>();
        if (status != null && status != 99) {
            param.put("status", status);
        }
        return projectInfoMapper.findListByMap(param);
    }

    @Override
    public ProjectInfo findById(Long id) {
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        List<ProjectInfo> projectInfoList = projectInfoMapper.findListByMap(param);
        if (null == projectInfoList) {
            return null;
        }
        return projectInfoList.get(0);
    }

    @Override
    public Integer modifyStatus(Long id, Integer status) {
        Assert.notNull(id, "Id不能为空");
        Assert.notNull(status, "status不能为空");
        Map<String, Object> param = new HashMap<>();
        param.put("id", id);
        param.put("status", status);
        return projectInfoMapper.modify(param);
    }
}
